<!DOCTYPE html>
<html>
<head>
    <title>收费项目管理</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../../Css/style.css"/>
    <script type="text/javascript" src="../../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../../Js/ckform.js"></script>
    <script type="text/javascript" src="../../Js/common.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }

        #total, #pages, #curPage {
            color: #1EABFF;
            padding: 0 5px;
        }

    </style>
    <script type="text/javascript">
        $(function () {
            $('#newNav').click(function () {
                window.location.href = "charge-new.html";
            });

            // 分页点击事件
            let $page = $("div[class='pagination']>ul>li");
            $page.click(function () {
                if (($(this).attr("class")) === 'disabled') {
                    return;
                }
                let num = $(this).attr("name");
                $("input[name='pageNum']").val(num);
                loadData();
            });

            loadData();
        });

        String.prototype.GetValue = function (para) {
            let reg = new RegExp("(^|&)" + para + "=([^&]*)(&|$)");
            let r = this.substr(this.indexOf("\?") + 1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        function loadData() {
            let $pageNum = $("input[name='pageNum']");
            let $pageSize = $("input[name='pageSize']");

            let url = document.location.toString();
            // 设置分页参数
            let pageNum = url.GetValue("pageNum");
            let pageSize = url.GetValue("pageSize");
            if (pageNum == null) {
                pageNum = $pageNum.val();
            }
            if (pageSize == null) {
                pageSize = $pageSize.val();
            }

            let hosrId = $("input[name='hosrId']").val();
            let hosrName = $("input[name='hosrName']").val();

            $.ajax({
                type: "GET",
                url: "/be-hosipital/list",
                dataType: "json",
                data: {
                    pageNum,
                    pageSize,
                    hosrId,
                    hosrName
                },
                success: function (res) {
                    console.log(res);
                    if (res.code === 200) {
                        let list = res.pageInfo.list;
                        let str = "";
                        for (let i = 0; i < list.length; i++) {
                            let obj = list[i];
                            let behId = obj.behId;
                            // let behState = obj.behState;
                            let hosrId = obj.hosrId;
                            let hosrName = obj.hosrName;
                            let behIntime = obj.behIntime == null ? '' : obj.behIntime;

                            /*let state = obj.reg.hosrState;
                            let beHState = "";
                            if (state == 0) {
                                beHState = "已挂号";
                            } else if (state == 1) {
                                beHState = "已住院";
                            } else if (state == 2) {
                                beHState = "已出院";
                            } else if (state == 3) {
                                beHState = "已退号";
                            }*/

                            let options =
                                `<a href="account-look2.html?behId=${behId}">详情</a>`;
                            options += `&nbsp;&nbsp;&nbsp;<a href="charge-new.html?behId=${behId}">添加收费项</a>`;

                            str += '<tr>' +
                                '            <td>' + hosrId + '</td>' +
                                '            <td>' + hosrName + '</td>' +
                                '            <td>' + behIntime + '</td>' +
                                '            <td>' + options + '</td>' +
                                '</tr>'
                        }
                        $("#tboby").html(str);
                        // 填充分页数据
                        fillPageData(res.pageInfo);
                    } else {
                        alert("系统开小差了");
                    }
                }
            });
        }

        // 填充分页信息
        function fillPageData(pageInfo) {
            //填充信息
            $("#total").html(pageInfo.total);
            $("#pages").html(pageInfo.pages);
            $("#curPage").html(pageInfo.pageNum);
            $("input[name='pageNum']").val(pageInfo.pageNum);
            $("select[name='pageSize']").val(pageInfo.pageSize);
            //设置按钮的属性值和样式
            $("#firstPage").attr("name", 1);
            $("#prePage").attr("name", pageInfo.prePage);
            $("#nextPage").attr("name", pageInfo.nextPage);
            $("#lastPage").attr("name", pageInfo.pages);
            $("#firstPage").removeClass("disabled");
            $("#prePage").removeClass("disabled");
            $("#nextPage").removeClass("disabled");
            $("#lastPage").removeClass("disabled");
            if (pageInfo.isFirstPage) {//如果是第一页：上一页和首页禁用
                $("#firstPage").addClass("disabled");
                $("#prePage").addClass("disabled");
            }
            if (pageInfo.isLastPage) {//如果已经是最后一页：下一页和末页禁用
                $("#nextPage").addClass("disabled");
                $("#lastPage").addClass("disabled");
            }

            // 删除原有内容
            $(".pageNode").remove();

            // 添加新内容
            let prePage = $("#prePage");
            // 设置页签
            let navigatepageNums = pageInfo.navigatepageNums;
            var s = "";
            navigatepageNums.map(index => {
                let curPageClass = pageInfo.pageNum == index ? 'color: red' : '';
                s +=
                    `<li class="pageNode" name="${index}" onclick="pageChange(${index})"><a href="#" style="${curPageClass}">${index}</a></li>`;

            });
            prePage.after(s);
        }

        function pageChange(mode) {
            $("input[name='pageNum']").val(mode);
            loadData();
        }

        function checkall() {
            var alls = document.getElementsByName("check");
            var ch = document.getElementById("checkall");
            if (ch.checked) {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = true;
                }
            } else {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = false;
                }
            }
        }

        function delAll() {
            var alls = document.getElementsByName("check");
            var ids = new Array();
            for (var i = 0; i < alls.length; i++) {
                if (alls[i].checked) {
                    ids.push(alls[i].value);
                }
            }
            if (ids.length > 0) {
                if (confirm("确认操作?")) {
                    alert("成功!");
                }
            } else {
                alert("请选中要操作的项");
            }
        }

        // 清除查询条件
        function clearOption() {
            let options = $("#searchArea > td > input");
            // console.log(options)
            for (let i = 0; i < options.length; i++) {
                let op = options[i];
                $(op).val("");
            }
        }

        $(function () {
            $('#backid').click(function () {
                window.location.href = "dispensing.html";
            });
        });
    </script>
</head>
<body>

<form action="charge.html" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr id="searchArea">
            <td width="10%" class="tableleft">病历号：</td>
            <td><input type="text" name="hosrId" value=""/></td>

            <td width="10%" class="tableleft">姓名：</td>
            <td><input type="text" name="hosrName" value=""/></td>
        </tr>
        <tr>
            <td colspan="4">
                <center>
                    <button onclick="loadData()" class="btn btn-primary" type="button">查询</button>
                    <button onclick="clearOption()" class="btn btn-primary" type="button">清空</button>
                </center>
            </td>
        </tr>
    </table>
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th>病历号</th>
        <th>姓名</th>
        <th>住院日期</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tboby">
    <tr>
        <td style="vertical-align:middle;">1103</td>
        <td style="vertical-align:middle;">黄飞鸿</td>
        <td style="vertical-align:middle;">2015-01-04 10:34:33</td>
        <td style="vertical-align:middle;">
            <a href="account-look2.html">详情</a>
            <a href="charge-new.html">添加收费项</a>
        </td>
    </tr>
    </tbody>
</table>

<input name="pageNum" value="1" type="hidden">
<input name="pageSize" value="5" type="hidden">
<!-- 2.分页部分 -->
<div class="form-group" style="float: right">
    <div class="col-sm-3" style="float: right; margin-right: 24px">
        <div class="pagination">
            <ul>
                <li name="pageLi" id="firstPage"><a href="javascript:void(0)">首页</a></li>
                <li name="pageLi" id="prePage"><a href="javascript:void(0)">上一页</a></li>
                <li name="pageLi" id="nextPage"><a href="javascript:void(0)">下一页</a></li>
                <li name="pageLi" id="lastPage"><a href="javascript:void(0)">末页</a></li>
            </ul>
        </div>
    </div>
    <div class="col-sm-1" style="float: right; padding-top: 5px; margin-right: 24px">
        <div class="pagination">
            <ul>
                共<span id="total"></span>条数据, 共<span id="pages"></span>页,当前第<span id="curPage"></span>页
            </ul>
        </div>
    </div>
</div>

</body>
</html>
